<template>
	<view class="">
		<!-- 头部标题 -->
		<view class="cu-bar bg-white">
			<view class="action sub-title">
				<text class="text-xl text-bold text-green">学生详细</text>
				<text class="bg-green"></text>
				<!-- last-child选择器-->
			</view>
		</view>
		<!-- 头部标题 end -->
		
		
		<!-- 学生信息 -->
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action">
				<text class="cuIcon-title text-orange"></text> 学生基本信息
			</view>
		</view>
		
		<view style="padding: 20upx; width: 100%;display: flex;justify-content: space-around;align-items: center;" class="bg-white">
			
			<image src="../../../static/logo.png" style="height: 100upx; width: 100upx;"></image>
			
			<text style="font-weight: 550;">{{studentName}}</text>
			
			<text style="font-weight: 550;margin-top: 10upx;">{{idcard}}</text>
			
		</view>
		
		<!-- end -->
		
		<!-- 选项卡 -->
		
		<scroll-view scroll-x class="bg-white nav text-center">
			<view class="cu-item" :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in 3" :key="index" @tap="tabSelect" :data-id="index">
				{{Title[index]}}
			</view>
		</scroll-view>
		<!-- end -->
		
		
		<!-- 内容区域 -->
		
		<!-- 考勤 -->
		<view v-if="TabCur == 0" class="">
			<!-- 历史内容区域 --> 
			<view class=" bg-white" style="padding: 10upx;" >
				
				<view class="shadow-warp " v-for="(item,index) in CheckWorkdData" :key="index" style="margin-top: 5upx;padding: 10upx;">
					
				<view class="" style="margin-top: 10upx;width: 100%;" >
					
				<view class="" style="display: flex;align-content: center;align-items: center;">
					
					<view class="" style="margin-right: 20upx;margin-top: 10upx;">
						<text style="font-weight: 550;font-size: 30upx;">{{item.createdAt}}</text>
					</view>
					
					<view>
						<text style="font-size: 30upx; font-weight: 550;">
							{{ getWeek(new Date(item.createdAt) ) }} 签到</text>
					</view>
					
				</view>
				
				<view class="" style="display:flex;justify-content: flex-end;margin-right: 20upx;">
					<text style="font-weight: 550;color: #AAAAAA;">已签到</text>
				</view>
				
				
					<view class=""></view>
					<text style="font-size: 25upx;color: #888888;font-weight: 550;">{{item.createdTime}}</text>
					</view>
					
				</view>
			</view>
		</view>
		<!-- 考勤 end -->
		
		<!-- 作业 -->
		<view v-if="TabCur == 1" class="">
			<view @click.native="toWorkUploadPage(index)" style="width: 100%;margin-bottom: 20upx;" class="shadow-warp" v-for="(item,index) in WorkdData" :key="index">
				
				<view class="bg-white" style="display: flex;padding: 20upx;">
					
					<image :src=" apiweb + item.img.split(',')[0] " style="height: 150upx;width: 150upx;border-radius: 20upx;"></image>
					
					<view style="margin-left: 20upx;display: flex;flex-direction: column;width: 75vw;"  >
						<view class="" style="display: flex;">
							<text class="text-cut" style="font-weight: 550;width: 60vw;">{{item.workName}}</text>
							<text class="" :style="'' + [item.status == 0 ? 'font-weight: 550; ' : 'font-weight: 550; color: #39B54A;']">{{item.status == 0 ? '未批改':'已批改'}}</text>
						</view>
						
						<view class="" style="margin-top: 50upx;display:flex;justify-content: space-between;align-items: center;">
							<text>共{{item.num}}到题目</text>
							<text style="margin-top: 5upx;">{{item.createdAt}}</text>
							<text style="color: red;">{{item.score}}分</text>
						</view>
						
					</view>
					
				</view>
				
				
			</view>
		</view>
		<!-- end -->
		
		<!-- 答题 -->
		<view v-if="TabCur == 2" class="">
			
			<view v-for="(item,index) in AnswerData" :key="index" class="bg-white padding shadow-warp" style="margin-bottom: 10upx;display: flex;width: 100%;display: flex;justify-content: space-around;">
				<text style="font-weight: 550;">{{item.createdAt}}</text>
				<text style="font-weight: 550;"><text style="color: red;margin-right: 5upx;">+ 5</text>分</text>
			</view>
			
		</view>
		<!-- end -->
		
		<!-- end -->
		
	</view>
</template>

<script>
	var _this;
	export default{
		data(){
			return{
				apiweb:"http://39.96.88.209:8080",
				classId:'',//课程id
				TabCur: 0,
				Title:["考勤","作业","答题"],
				scrollLeft:0,
				studentName:"",//姓名
				idcard:'',//学号,
				studentId:'',//学生id
				CheckWorkdData:null,//考勤数据
				WorkdData:null,//作业数据列表
				AnswerData:'',//答题
				
			}
		},
		methods:{
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
				
				if(_this.TabCur == 0){//考勤
					_this.getCheckWorkdData();
				}else if(_this.TabCur == 1){//作业
					_this.getWorkdData();
				}else if(_this.TabCur == 2){//答题
					_this.getAnswerData();
				}
				
			},
			
			// 跳转作业详细
			toWorkUploadPage:function(index){
				var data =  _this.WorkdData[index];
				var list =  data.img.split(',');
				console.log(data);
				uni.navigateTo({
					url: '/pages/classDesc/classDesc_t/SutdentDeasWorkDesc_t?classId='+_this.classId + "&listImage=" + list + "&uid=" + data.uid + "&workId=" + data.workId,
				});
			},
			
			// 考勤数据
			getCheckWorkdData(){
				uni.showLoading({
					title:"数据加载中..."
				})
				uni.request({
					url:_this.api + "Qian/getAll",
					data:{
						uid:_this.studentId,
						clazzId:_this.classId
					},
					header:{
						 "content-type":"application/x-www-form-urlencoded"
					},
					method:"POST",
					success: (res) => {
						uni.hideLoading();
						_this.CheckWorkdData = res.data.data;
						console.log(res)
						
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							title:"考勤数据获取失败！请稍后在试~~",
							duration:1000,
							icon:"none"
						})
					}
					
				})
			},
			// 作业数据
			getWorkdData(){
				uni.showLoading({
					title:"数据加载中...",
					
				})
				uni.request({
					url:_this.api + "work/list",
					data:{
						clazzId:_this.classId,
						uid:_this.studentId
					},
					header:{
						"content-type":"application/x-www-form-urlencoded"
					},
					method:"POST",
					success: (res) => {
						uni.hideLoading();
						_this.WorkdData = res.data.data;
						console.log(res);
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							title:"作业数据获取失败！请稍后在试~~",
							duration:1000,
							icon:"none"
						})
					}
					
				})
			},
			// 答题数据
			getAnswerData(){
				uni.showLoading({
					title:"数据加载中..."
				})
				uni.request({
					url:_this.api + "answer/studentHistory",
					data:{
						uid:_this.studentId,
					},
					header:{
						"content-type":"application/x-www-form-urlencoded"
					},
					method:"POST",
					success: (res) => {
						uni.hideLoading();
						_this.AnswerData = res.data.data;
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							title:"答题数据获取失败！请稍后在试~~",
							duration:1000,
							icon:"none"
						})
					}
					
				})
			},
			
		//根据时间判断星期几
			getWeek(timedat) {
				//timedat参数格式：   getWeek（new Date("2017-10-27" )）
			   var week;
			  if(timedat.getDay() == 0) week = "星期日";
			  if(timedat.getDay() == 1) week = "星期一";
			  if(timedat.getDay() == 2) week = "星期二";
			  if(timedat.getDay() == 3) week = "星期三";
			  if(timedat.getDay() == 4) week = "星期四";
			  if(timedat.getDay() == 5) week = "星期五";
			  if(timedat.getDay() == 6) week = "星期六";
		  return week;  
			  }
			
		},
		onLoad(optins) {
			_this = this;
			_this.studentName = optins.studentName;
			_this.idcard = optins.idcard;
			_this.classId = optins.classId;
			_this.studentId = optins.studentId;
			_this.getCheckWorkdData();
		}
	}
</script>

<style>
</style>
